home *** CD-ROM | disk | FTP | other *** search
- PROGRAM Stats; { (C) 1991 John C. Leon last updated 11/9/91 }
-
- {
- This program will report stats on ANY Btrieve file. Just supply the name of
- any valid Btrieve file on the command line or when prompted. We are not
- concerned with the record layout of a file at all in this program. We just
- want stats, to illustrate use of the BFile object.
- }
-
- {$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}
-
- USES
- BTP; {Crt unit not used at all, to permit redirection of program output
- to file or printer.}
-
- TYPE
- PStatFile = ^TStatFile;
- TStatFile = object(BFile)
- KeyType: string;
- procedure SetKeyType(KFlags: integer; EType: byte);
- end;
-
- VAR
- StatFile : PStatFile;
- StatFileName,
- KeyType, TempS,
- S1, S2 : string;
- Counter,
- KeyCount : integer;
- PriorSegmented,
- HasDescKey : boolean;
-
- procedure TStatFile.SetKeyType(KFlags: integer; EType: byte);
- begin
- if (KFlags and Binary) = Binary then
- KeyType := 'Unsigned'
- else
- begin
- case EType of
- 0: KeyType := 'String ';
- 1: KeyType := 'Integer ';
- 2: KeyType := 'Float ';
- 3: KeyType := 'Date ';
- 4: KeyType := 'Time ';
- 5: KeyType := 'Decimal ';
- 6: KeyType := 'Money ';
- 7: KeyType := 'Logical ';
- 8: KeyType := 'Numeric ';
- 9: KeyType := 'Bfloat ';
- 10: KeyType := 'Lstring ';
- 11: KeyType := 'Zstring ';
- 14: KeyType := 'Unsigned';
- 15: KeyType := 'AutoInc ';
- end;
- end;
- end;
-
- procedure DoFileStatLine;
- begin
- if length(S1) < 37 then
- for Counter := length(S1) to 37 do
- S1 := S1 + ' ';
- writeln(S1, S2);
- end;
-
-
- BEGIN
- {get filename to act on and store it in uppercase}
- if paramcount < 1 then
- begin
- write('Enter name of a Btrieve file: ');
- readln(StatFileName);
- end
- else
- StatFileName := paramstr(1);
- for Counter := 1 to length(StatFileName) do
- StatFileName[Counter] := upcase(StatFileName[Counter]);
-
- {open the file in read only mode}
- StatFile := new(PStatFile, Init(StatFileName, ReadOnly));
-
- if BStatus <> 0 then
-
- writeln('Error opening Btrieve file. Program terminated.')
-
- else
-
- begin
-
- HasDescKey := false;
-
- writeln;
- writeln('BTP Stats - Version 1.5 - (C) 1991 John C. Leon. All Rights Reserved.');
- writeln;
- writeln('File stats for ', StatFileName);
- writeln;
-
- with StatFile^ do
- begin
- str(Specs.RecLen, TempS);
- S1 :=('Record length = ' + TempS);
- S2 := 'Variable Length = ';
- if (Specs.FileFlags and VarLength) = VarLength then
- begin
- S2 := S2 + 'Yes Free Space = ';
- if (Specs.FileFlags and Free30) = Free30 then
- S2 := S2 + '30%' else
- if (Specs.FileFlags and Free20) = Free20 then
- S2 := S2 + '20%' else
- if (Specs.FileFlags and Free10) = Free10 then
- S2 := S2 + '10%' else
- S2 := S2 + '0%';
- end
- else
- S2 := S2 + 'No';
- DoFileStatLine;
- str(Specs.NumKeys, TempS);
- S1 := 'Number keys/segs = ' + TempS + ' / ';
- str(NumSegs, TempS);
- S1 := S1 + TempS;
- S2 := 'Blank Truncation = ';
- if (Specs.FileFlags and BlankTrunc) = BlankTrunc then
- S2 := S2 + 'Yes' else S2 := S2 + 'No';
- DoFileStatLine;
- str(Specs.UnusedPgs, TempS);
- S1 := 'Unused pages = ' + TempS;
- S2 := 'Preallocation = ';
- if (Specs.FileFlags and PreAllocate) = PreAllocate then
- begin
- str(Specs.PreAlloc, TempS);
- S2 := S2 + 'Yes Pages = ' + TempS;
- end
- else
- S2 := S2 + 'No ';
- DoFileStatLine;
- str(Specs.PageSize, TempS);
- S1 := 'Page size = ' + TempS;
- S2 := 'Data Compression = ';
- if (Specs.FileFlags and DataComp) = DataComp then
- S2 := S2 + 'Yes' else S2 := S2 + 'No';
- DoFileStatLine;
- str(NumRecs, TempS);
- S1 := 'Number records = ' + TempS;
- S2 := 'Key Only File = ';
- if (Specs.FileFlags and KeyOnly) = KeyOnly then
- S2 := S2 + 'Yes' else S2 := S2 + 'No';
- DoFileStatLine;
- writeln;
- write('Key Position Length Duplicates Modifiable Type ');
- writeln('Null Total');
- writeln;
-
- KeyCount := 0;
- PriorSegmented := false;
-
- for Counter := 1 to NumSegs do
- with Specs.KeyArray[Counter-1] do
- begin
- write(KeyCount:3, KeyPos:8, KeyLen:8, ' ');
- if (KeyFlags and Segmented) = Segmented then
- PriorSegmented := true;
- if (KeyFlags and Segmented) <> Segmented then
- PriorSegmented := false;
- if ((KeyFlags and Segmented) <> Segmented) and
- (PriorSegmented = false) then inc(KeyCount);
- if (KeyFlags and Duplicates) = Duplicates then
- write('Yes') else write(' No');
- if (KeyFlags and Modifiable) = Modifiable then
- write(' Yes ') else write(' No ');
- SetKeyType(KeyFlags, ExtKeyType);
- if (KeyFlags and AltCol) = AltCol then
- write(' *', KeyType) else write(' ', KeyType);
- if (KeyFlags and Descending) = Descending then
- begin
- write(' <');
- HasDescKey := true;
- end
- else
- write(' ');
- if (KeyFlags and Null) = Null then
- write(NullValue) else write('-- ');
- write(NumUnique: 10);
- writeln;
- if (Counter + 13) = 23 then
- begin
- writeln;
- writeln('-- press Enter to continue');
- readln; writeln;
- end;
-
- end; {with Specs.KeyArray[Counter-1] do}
-
- if HasAltCol then
- begin
- writeln;
- write('* Alternate Collating Sequence is: ');
- for Counter := 1 to 8 do
- write(AltColName[Counter]);
- end;
-
- if HasDescKey then
- begin
- writeln;
- write('< Indicates descending key segment');
- end;
-
- writeln;
-
- BStatus := Close;
-
- end; {with StatFile^ do}
-
- if BStatus <> 0 then
- writeln('File could not be closed. Status = ', BStatus);
-
- end; {if BStatus <> 0}
-
- dispose(StatFile, Done);
-
- END.
-